package com.wang.test.demo.putong;

public class ExtendInterface {
    /**
     * 让天鹅和鸵鸟下蛋 哈哈哈哈...
     */
    public static void main(String[] args) {
        EggLayable swanEggLay = new Swan();
        swanEggLay.eggLay();
        Swimmingable swimmingable = new Swan();
        swimmingable.swimming();
        EggLayable ostrichEggLay = new Ostrich();
        ostrichEggLay.eggLay();
    }
}

// 天鹅
class Swan implements Flyable, Swimmingable, EggLayable {
    Flyable flyAbility = new FlyAbility(); // 组合
    Swimmingable swimmingAbility = new SwimmingAbility();// 组合
    EggLayable eggAbility = new EggAbility();// 组合

    public Swan(){System.out.println("我是天鹅");}

    @Override //委托
    public void fly() { flyAbility.fly();}

    @Override //委托
    public void swimming() {  swimmingAbility.swimming();}

    @Override //委托
    public void eggLay() { eggAbility.eggLay();}
}

class Ostrich implements EggLayable { //鸵鸟
    EggLayable eggAbility = new EggAbility();// 组合
    public Ostrich(){ System.out.println("我是鸵鸟"); }
    @Override
    public void eggLay() {eggAbility.eggLay(); } //委托
}

// interface
interface Flyable { void fly();}

interface Swimmingable { void swimming();}

interface EggLayable { void eggLay();}

// 公共方法的实现类
class FlyAbility implements Flyable {
    @Override
    public void fly() {System.out.println("飞一会儿"); }
}
// 公共方法的实现类
class SwimmingAbility implements Swimmingable {
    @Override
    public void swimming() { System.out.println("游泳"); }
}
// 公共方法的实现类
class EggAbility implements EggLayable {
    @Override
    public void eggLay() {System.out.println("下一颗蛋"); }
}


